import {findEnumMap} from "@/api/system/sysEnum/sysEnum"
import store from '@/store'

export default function(Vue, options) {
  Vue.mixin({
    data() {
      if (this.$options === undefined || this.$options.sysEnums === undefined || this.$options.sysEnums === null) {
        return {}
      }
      const sysEnum = {
        sysEnumInit: true
      }
      return {
        sysEnum
      }
    },
    created() {
      if (this.sysEnum && this.sysEnum.sysEnumInit){
        //store里面加载一遍，没有就获取接口 findEnumMap

        //需要的枚举对象
        for (const sysEnumKey of this.$options.sysEnums) {
          //有的枚举对象
          var item = this.$store.getters.sysEnum[sysEnumKey];
          // 存在对象
          if (!item){
            // 不存在根据接口读取值
            findEnumMap(sysEnumKey).then(res=>{
              this.sysEnum[sysEnumKey] = res
              store.dispatch("sysEnum/setSysEnum",{key:sysEnumKey,value:res})
            })
          }else {
            this.sysEnum[sysEnumKey] = item
          }
          for (const sysEnumKey in this.$store.getters.sysEnum) {
            store.dispatch("sysEnum/setSysEnum",{key:1,value:123})
          }
        }
      }
    },
  })
}
